import rMath from "shared/component/common/rMath";
import HotClass from "shared/component/hotconfig/HotClass";
import Log4R from "shared/component/log/Log4R";
import { setTimeOut } from "shared/component/time/SetTime";
import { CharacterState } from "shared/enums/CharacterState";
import { ColiGroup } from "shared/enums/ColiGroup";
const loginfo = Log4R.getLog('info');
export default class ActController extends HotClass implements Ctn.move.ActController {
    dodge(characterEntity: Ctn.character.CharacterEntity, enable: boolean): boolean {

        return false
    }

    jump(characterEntity: Ctn.character.CharacterEntity, enable: boolean) {
        // loginfo?.info('enable', enable)

        const humanModel = characterEntity.character
        if (!humanModel) return
        const velocity = humanModel.HumanoidRootPart.ActVelocity;

        velocity.Enabled = enable

        if (enable) {
            velocity.RelativeTo = Enum.ActuatorRelativeTo.World
            velocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Line
            // loginfo?.info('state.moveState?.vector', characterEntity.moveState?.orientation)
            velocity.LineDirection = rMath.vectors.up;
            velocity.LineVelocity = 30
            velocity.MaxForce = 10000
            characterEntity.actConnector?.Disconnect();
            // humanModel.HumanoidRootPart.CollisionGroup = ColiGroup.characterJump;
            const actConnector = setTimeOut(0.05, () => {
                actConnector.Disconnect();
                velocity.Enabled = false;
                // humanModel.HumanoidRootPart.CollisionGroup = ColiGroup.character;
            })
            characterEntity.actConnector = actConnector
        }

    }
    /** 改变碰撞组 */
    public changeColli(state: CharacterState, characterEntity: Ctn.character.CharacterEntity) {
        if (
            state === CharacterState.Jumping ||
            state === CharacterState.DownJumping ||
            state === CharacterState.DownFalling) {
            const character = characterEntity.character;
            if (!character) return
            characterEntity.afterChangeJumpColiGroupTime?.Disconnect();
            character.HumanoidRootPart.CollisionGroup = ColiGroup.characterJump;
            let time = 0.15;
            if (state === CharacterState.Jumping) {
                time = 0.3;
            }
            /** 定时恢复碰撞组的计时器 */
            const afterChangeJumpColiGroupTime = setTimeOut(time, () => {
                character.HumanoidRootPart.CollisionGroup = ColiGroup.character;
                loginfo?.info('恢复碰撞组事件');
            })
            characterEntity.afterChangeJumpColiGroupTime = afterChangeJumpColiGroupTime
            loginfo?.info('changeColli 改变碰撞组事件',
                character.HumanoidRootPart.AssemblyLinearVelocity,
                CharacterState[state], character.HumanoidRootPart.CollisionGroup)
        }
        // else if (state !== CharacterState.Standing) {
        //     // character.HumanoidRootPart.CollisionGroup = ColiGroup.character;
        // }

    }
}